In the event of technical difficulties with Szkopuł, please contact us via email at [email protected].
If you would like to talk about tasks, solutions or technical problems, please visit our Discord servers. They are moderated by the community, but members of the support team are also active there.
Little Sophie gives a birthday party. She has written a tentative list of her kindergarten friends she would like to invite. However, kids are very demanding guests. Mary said she should come, but only provided Camille and Emily are not present, for they took her doll last week. Little Christopher only plays with Sophie and Camille and he does not wish to see any other kids at the party. And so on...
Sophie considers a party a success if none of the guests invited has objection against any other's presence. She has decided not to invite certain kids to assure that the party is a success. On the other hand she would like to invite as many kids as possible. Should Sophie not be able to invite at least kids she won't give any party at all.
Help little Sophie! Write a programme which:
The first line of the standard input contains two positive integers separated by a single space: - the number of all Sophie's acquaintances () and - the minimal number of kids Sophie wishes to invite to the party (). The kids are assigned numbers from the range to .
The following lines contain a description of kids' demands. In the second line there is a single integer , . Each of the following lines contains a pair of integers , , separated by a single space (, ). You can assume that each (ordered) pair appears in the standard input once at the most. The pair , denotes that the child does not wish to meet child at the party.
If it is not possible to invite kids to the party so that it is a success then the first and only line of the standard output should contain a single word: NIE.
If it is possible, then the first line of the standard input should contain a single integer - the maximal number of kids that can be invited to the party so that it is a success. The second line of the standard output should contain the numbers of kids to be invited, separated by single spaces, in increasing order. Should there be more correct answers your programme should write out any one of them.
For the input data:
9 4 12 9 6 4 6 7 9 1 2 2 1 9 7 7 6 4 5 7 8 8 9 3 4 4 3
the correct result is:
5 1 3 5 6 8
Task author: Lukasz Kowalik.